package com.tanhua.server.controller;

import com.tanhua.server.service.RecommendUserService;
import com.tanhua.utils.Cache;
import com.tanhua.server.vo.PageResult;
import com.tanhua.server.vo.RecommendUserQueryParam;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("tanhua")
@Slf4j
public class RecommendUserController {

    @Autowired
    private RecommendUserService recommendUserService;

    @Autowired
    private RedisTemplate redisTemplate;

    @GetMapping("recommendation")
    @Cache
    public ResponseEntity<PageResult> queryRecommendation(@RequestHeader("Authorization") String token, RecommendUserQueryParam recommendUserQueryParam){


        try {
            PageResult pageResult = recommendUserService.queryRecommendation(token,recommendUserQueryParam);
            if (null != pageResult){
                return ResponseEntity.ok(pageResult);
            }
        } catch (Exception e) {
            log.error("查询推荐列表出错,token="+token);
        }

        return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(null);
    }

}
